package com.simpleplayer.services;

public class TimeUtil {
    public static final String STRING_TIME_MAX = "99:59:59";

    /**
     * 秒转换时:分:秒
     * @param seconds 秒为单位 比如..600秒
     * @return 比如...02:03:52
     */
    public static String secToTime(long seconds) {
        int hour = (int)(seconds / 3600);
        int minute = (int)((seconds - hour * 3600) / 60);
        int second = (int)(seconds - hour * 3600 - minute * 60);

        if (hour >= 100) {
            return STRING_TIME_MAX;
        }

        StringBuilder time = new StringBuilder();
        if (hour >= 10) {
            time.append(hour).append(":");
        } else if (hour > 0) {
            time.append("0").append(hour).append(":");
        }

        if (minute >= 10) {
            time.append(minute).append(":");
        } else if (minute > 0) {
            time.append("0").append(minute).append(":");
        } else {
            time.append("00:");
        }

        if (second >= 10) {
            time.append(second);
        } else if (second > 0) {
            time.append("0").append(second);
        } else {
            time.append("00");
        }

        return time.toString();
    }

    /**
     * 获取当前系统时间
     * @return 当前时间，单位：ms
     */
    public static long getCurrentTimeMillis() {
        return System.currentTimeMillis();
    }
}
